package cn.itsource.order.controller;

import cn.itsource.order.service.IOrderProductService;
import cn.itsource.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/productOrder")
public class OrderProductController {

    @Autowired
    private IOrderProductService orderProductService;

    @PostMapping("/create")
    public AjaxResult createOrder(@RequestBody Map<String,String> map, HttpServletRequest request){
        System.out.println(map);//{productId=180, addressId=1, pay=ALIPAY}
        try {
            return  orderProductService.createOrder(map,request);
        } catch (Exception e) {
            e.printStackTrace();
            return  AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }
}
